import { configureStore } from '@reduxjs/toolkit'
import { combineReducers } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import useSettingStore from '@/redux/modules/settings'
import useMenuStore from '@/redux/modules/menu'
import usePermission from '@/redux/modules/permission'
import useUserStore from "@/redux/modules/user";

const reducer = combineReducers({
    useSettingStore,
    useMenuStore,
    usePermission,
	useUserStore
})

// redux 持久化配置
const persistConfig = {
	key: 'redux-state',
	storage: storage,
    blacklist: ['useMenuStore', 'usePermission'] // 不需要缓存的数据
}

// 将数据放入持久化reducer中
const persistReducerConfig = persistReducer(
	persistConfig,
    reducer
)
const store = configureStore({
	reducer: persistReducerConfig,
	middleware: (getDefaultMiddleware) =>
		getDefaultMiddleware({
			//关闭redux序列化检测
			serializableCheck: false,
		}),
})
// 创建持久化 store
export const persistor = persistStore(store)

export default store
